//
//  UIViewController+DYLoadView.m
//  DYHospital
//
//  Created by 胡金东 on 16/3/23.
//  Copyright © 2016年 胡金东. All rights reserved.
//

#import "UIViewController+DYLoadView.h"
#import "MBProgressHUD.h"
#import "BSMacros.h"

@implementation UIViewController (DYLoadView)



/**
 * 显示提示信息
 */
- (void)showHint:(NSString *)msg
{
    [self showHint:msg inCenter:NO];
}

/**
 * 显示提示信息
 */
- (void)showHint:(NSString *)msg inCenter:(BOOL)inCenter
{
    if (msg == nil || [msg stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceAndNewlineCharacterSet]].length == 0) {
        return;
    }
    MBProgressHUD *hud = [MBProgressHUD showHUDAddedTo:[self mainWindow] animated:YES];
    hud.mode = MBProgressHUDModeText;
    hud.animationType = MBProgressHUDAnimationZoom;
    hud.tag = 102;
    hud.removeFromSuperViewOnHide = YES;
    hud.detailsLabelText = msg;
    hud.detailsLabelFont = [UIFont systemFontOfSize:14.0f];
    hud.margin = 10.0f;
    hud.yOffset = IS_IPHONE_5 ? 180 : 140;
    if (inCenter) {
        hud.yOffset = .0f;
    }
    [hud hide:YES afterDelay:1.0f];
}

- (UIWindow *)mainWindow
{
    UIApplication *app = [UIApplication sharedApplication];
    if ([app.delegate respondsToSelector:@selector(window)])
    {
        return [app.delegate window];
    }
    else
    {
        return [app keyWindow];
    }
}




@end
